<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script th:src="@{/static/main.js}"></script>


</head>
<body>



<div class="container-fluid" id="app" style="margin-top: 5px;margin-bottom: 100px">


        <div class="row" style="margin-top: 20px">
            <nav class="nanbar navbar-default " role="navigation">
                <div class="container"  >
                    <div class="navbar-header" >
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="navbar-collapse">
                            <span class="sr-only"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a  style="cursor: pointer" class="navbar-brand" :href="'/store/toStoreMenu?storeId='+storeVo.id" v-text="storeVo.storeName">Front College</a>
                    </div>
                    <div class="collapse navbar-collapse">
                        <form class="navbar-form navbar-right">
                            <div class="form-group">
                                <input v-model="keyword" type="text" name="searchName" class="form-control" id="search"
                                       placeholder="请输入商品名">
                            </div>
                            <button type="submit" class="btn btn-default" @click.prevent="toSearch">🔍</button>
                            <button type="button" class=" btn btn-primary"  onclick="window.history.go(-1)"><strong>返回</strong></button>
                        </form>
                        <ul class="nav navbar-nav navbar-right"  style="cursor: pointer" v-for="productType in productTypes">
                            <li :class="addClass(productType.id) "  v-bind:value="productType.id">
                                <a class="nav-link " v-text="productType.typeName" @click.prevent="toPass(productType.id)"></a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>

        </div>
        <div class="row">
            <div class= "col-md-8">
                <h4 class="text-primary">地址 : <span v-text="storeVo.address"></span></h4>
                <h4 class="text-primary">简介 : <span v-text="storeVo.detail"></span></h4>
            </div>
        </div>
        <div class="container" v-if="products.length<=0">
            <h3 style="text-align: center" class="text-danger">该商店没有相关商品哦~</h3>
        </div>

        <div class="container"   v-if="products.length>0">
            <div class="col-sm-6 col-md-4"  v-for="product in products">
                <div class="thumbnail" style="cursor:pointer;padding-bottom: 20px" @click="toDetail(product.id)">
                    <img v-if="!product.productImg" src="/static/109951166155909486.jpg" alt="..." class="col-sm-6 col-md-6">
                    <img v-if="product.productImg" :src="product.productImg" alt="..." class="col-sm-6 col-md-6">

                    <div class="caption text-left">
                        <h3> <span  v-text="product.productName">name</span></h3>
                        <p><span class="text-danger" v-text="'￥'+product.productPrice + '元'">price</span></p>
                        <p>销售量:<span v-text="product.buyCount">buyCount</span></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-offset-5 col-lg-offset-4col-xl-offset-5">
                <ul class="pagination justify-content-center">
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
                    <li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a>
                    </li>
                    <li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
                </ul>
            </div>
        </div>




</div>



</body>
</html>

<script>


    console.log(".........storemenu...........")

    let storemenu = new Vue({
        el: "#app"
        ,
        data: {
            products: [],
            storeId: [[${storeId}]],
            currentPage: 1,
            pageSize: 9,
            total: 0,
            totalPages: 0,
            storeVo:{},
            keyword: '',
            productType: 0,
            typeIdKeyword:'',
            productTypes:[],
            currentAccount: ''

        }
        ,
        methods: {
            initAllProducts() {
                let _this = this;
                let params = {
                    currentPage: _this.currentPage,
                    pageSize: _this.pageSize,
                    storeId: _this.storeId,
                    keyword: _this.keyword,
                    typeIdKeyword: _this.typeIdKeyword
                }

                console.log(params);
                $.post("/product/select", params, function (data) {

                    _this.products = data.records;
                    _this.currentPage = data.current;
                    _this.pageSize = data.size;
                    //数据总量
                    _this.total = data.total;
                    //总页数
                    _this.totalPages = data.pages;
                })

            }
            ,
            go(pageNum) {
                //小于1 或者 大于total 或者 仍获取当前页数据 直接返回
                if (pageNum < 1 || pageNum > this.totalPages || pageNum == this.currentPage) {
                    console.log(pageNum + " 无效页码值")
                    return;
                }

                this.currentPage = pageNum;
                this.initAllProducts();
            },
            initStoreDetails(){
                let _this=this
                $.get("/store/queryDetails",{storeId:_this.storeId},function (data){
                    _this.storeVo=data;
                })
            },
            toSearch() {

                this.initAllProducts();
            },
            toPass(productTypeId){
                this.typeIdKeyword=productTypeId;
                this.initAllProducts();
            },
            initProductTypes() {
                let _this = this;
                $.get("/productType/all",{storeId:_this.storeId},function (data) {
                    _this.productTypes = data;
                })
            },
            addClass(productId){
                if(productId==this.typeIdKeyword){
                    return"nav-item active"
                }else return "nav-item"
            },
            toDetail(productId){
                console.log(productId);
                window.location.href="/product/toProductDetail?productId="+productId
            }


        }
        ,
        created() {
            this.initAllProducts();
            this.initStoreDetails();
            this.initProductTypes();
        }

    });


</script>